<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>品牌列表</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />

        <base href="/static/">
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="username"  placeholder="请输入品牌名" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="xadmin.open('品牌添加','{{url("brand/brand_add")}}',600,400)"><i class="layui-icon"></i>添加</button>
                        </div>
                        <div class="layui-card-body ">
                            <!-- 展示数据 -->
                            <table class="layui-table layui-form" id="brand" lay-filter="brand"></table>

                        </div>

                    </div>
                </div>
            </div>
        </div>
    </body>
    <script type="text/html" id="barDemo">
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script>
      layui.use('table',function(){
        var table = layui.table;
        table.render({
          elem:"#brand",
          url:"{{url('brand/list_data')}}",
           // toolbar:'default',
          defaultToolbar: ['filter', 'print', 'exports'],
          title:'品牌列表',
          cellMinWidth:80, //全局定义单元格的最小宽度
          autoSort:true,
          page: true, //开启分页
          cols:[[
              {field:'brand_id',align:'center',title:'品牌ID',sort:true},
              {field:'brand_name',align:'center',title:'品牌名称'},
              {field:'brand_logo',align:'center',title:'品牌logo',templet: function(d){
                return '<img src="/'+d.brand_logo+'">';
              },event:"lookpic",style:"cursor:pointer"},
              {field:'brand_url',align:'center',title:'品牌链接'},
              {field:'brand_desc',align:'center',title:'品牌描述'},
              {field:'brand_sort',align:'center',title:'品牌排序',sort: true},
              {fixed: 'right', title:'操作', align:'center', toolbar: '#barDemo', width:150}
          ]]
        });

        //监听工具条
        table.on('tool(brand)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
          var data = obj.data; //获得当前行数据
          var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
          var tr = obj.tr; //获得当前行 tr 的DOM对象
          /*console.log(data);
          console.log(layEvent);
          console.log(tr);*/

          if(layEvent === 'del'){ //删除
            layer.confirm('真的要删除么？', function(index){
              obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
              layer.close(index); //向服务端发送删除指令
              $.ajax({
                url:"{{url('brand/brand_del')}}",
                data:data,
                success:function(res){
                  if (res == 1001) {
                    layer.msg(res.msg,{icon:res.code,time:1000});
                  }else{
                    layer.msg(res.msg,{icon:res.code,time:1000});
                  }
                }
              });
            });
          }else if(layEvent === 'edit'){ //编辑
            layer.open({ //弹出层
              title: '品牌修改',
              content:"{{route('brand_save')}}?brand_id="+data.brand_id,
              type:2,
              area: ['600px', '400px']
            });
          }else if(layEvent === 'lookpic'){ //查看大图
            layer.open({ //弹出层
              title: '查看大图',
              content:'<img src="/'+data.brand_logo+'" width="600px">',
              area: '600px'
            });
          }
        });

      });

      layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;

        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
      });


    </script>
</html>
